<?php
require 'header.php';
require 'includes/db.php';
$tableName='contact_us';
$where='';
  $id = isset($_GET['id']) ? $_GET['id'] : 0;
  $total_users = CountAll('contact_us');
  
  ########### Count total records in users table ##############

########### PAGING START ###########################

  $rpp = 2;// Record Per Page (offset)
  $total_pages = ceil($total_users / $rpp);
  $currentPage = isset($_GET['page']) ? $_GET['page'] : 1;
  $index = $rpp*($currentPage-1); // limit or from where we have to start fetching


?>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" >
	<h3>Contect_us</h3>
    <?php
     if(isset($_GET['mode'])) {
    $numRows = deleteby($tableName, $id);
	
    if($numRows == 1){
      echo success("Succefully Deleted");
    }
  }
    ?>

    <table class="table table-striped">
        <thead>
            <tr>
                <th width="15%" align="right">Name</th>
                <th width="15%" align="right">Phone Number</th>
                <th width="20%" align="right">Email Address</th>
                <th width="40%" align="right">Message</th>
                <th width="10%" align="right">Action</th>

            </tr>
        </thead>
        <?php
        $sql = fetchAll($tableName,$where,'id',$index,$rpp);
        while ($data = mysql_fetch_assoc($sql)) {
            ?>				<tbody>
                <tr>
                    <td><?= $data['name'] ?></td>
                    <td><?= $data['phone'] ?></td>
                    <td><?= $data['email'] ?></td>
                    <td><?= $data['message'] ?></td>
                    <td> <div><a onClick="return confirm('Are you sure to delete?')" href="?mode=del&id=<?=$data['id']?>&page=<?=$currentPage?>" class="delete"><span class="glyphicon glyphicon-trash" style="font-size:30px; color: red;"></span></a>&nbsp;&nbsp;&nbsp;</div> </td>


                <?php } ?>
    </table>
    <ul class="pagination pagination-lg">

  <li class="disabled"><a href="#">&laquo;</a></li>

<?php
  for ($i=1; $i <= $total_pages ; $i++) {
    if($i==$currentPage) {
?>
  <li class="active"><a href="#"><?=$i?> <span class="sr-only">(current)</span></a></li>

<?php
    } else { //end current page if()
?>
  <li><a href="?page=<?=$i?>"><?=$i?></a></li>
<?php
    } // end else
  }//end for() for paging
?>

  <li><a href="#">&raquo;</a></li>
</ul>
                </div>

